package www.dianbaozu.com.ui.server.channelDetail.holder

import android.util.Log
import android.view.View
import androidx.databinding.DataBindingUtil
import com.netease.nim.uikit.R
import com.netease.nim.uikit.api.NIMHelper
import com.netease.nim.uikit.api.SessionHelper
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseQuickAdapter
import com.netease.nim.uikit.common.ui.recyclerview.holder.BaseViewHolder
import com.netease.nim.uikit.common.ui.recyclerview.holder.RecyclerViewHolder
import com.netease.nim.uikit.databinding.ItemFriendsBinding
import www.wen.com.common.lib.data.entities.ServiceMemberEntity
import www.wen.com.common.lib.extension.getDrawableAgency
import www.wen.com.common.lib.extension.glide.setImageUrl
import www.wen.com.common.lib.extension.imgUrl

class ChannelDetailUserViewHolder(baseQuickAdapter: BaseQuickAdapter<Any, BaseViewHolder>) :
    RecyclerViewHolder<BaseQuickAdapter<Any, BaseViewHolder>, BaseViewHolder, Any>(
        baseQuickAdapter
    ) {
    private var binding: ItemFriendsBinding? = null

    override fun convert(
        holder: BaseViewHolder,
        data: Any,
        position: Int,
        isScrolling: Boolean
    ) {
        if (data is ServiceMemberEntity) {
            data.let { memberEntity ->
                binding = DataBindingUtil.bind(holder.itemView)
                binding?.apply {
                    tvSubtitle.visibility = View.GONE
                    imgArrow.visibility = View.GONE
                    tvTopStatus.visibility = View.GONE
                    slUnreadMessage.visibility = View.GONE
                    imgOnlineStatus.visibility = View.VISIBLE

                    ivAvatar.resetImageView()
                    ivAvatar.loadAvatar(memberEntity.avatar.imgUrl())
                    imgOnlineStatus.setImageResource(if (memberEntity.onlineStatus)
                        R.drawable.ic_circle_green_middle_1 else
                        R.drawable.ic_circle_gray_middle_1)
                    tvTitle.text = memberEntity.nickName
                    holder.addOnClickListener(R.id.constraintLayout)
                }
            }
        }
    }
}